import {
  ADOPTION_SOURCE_List,
  PET_STATE_LIST,
  IF_ILL_LIST,
} from '@/const/type';
import { numberValidate } from '@/util/validate';
export const tableOption = (isView, page) => {
  return {
    ...window.$crudMixins.tableOptions,
    addBtn: false,
    editBtn: false,
    delBtn: false,
    menuWidth: 260,
    labelWidth: 140,
    emptyBtn: false,
    submitBtn: false,
    detail: isView,
    column: [
      {
        label: '宠物快照',
        prop: 'avatar',
        type: 'upload',
        listType: 'picture-img',
        span: 12,
        fileSize: 10 * 1024,
        propsHttp: {
          name: 'hash',
          url: 'key',
        },
        fileType: 'img', //img/video/audio
        // action: 'http://upload-z2.qiniup.com',
        oss: 'qiniu',
        cropperOption: {
          enlarge: 2,
          fixed: true,
          fixedNumber: [0.83, 1],
        },
        tip: '请上传jpg/png/jpeg/webp/heic类型的文件，最大可上传10M',
        accept: '.jpg,.png,.jpeg,.webp,.heic',
        limit: 1,
        rules: [
          {
            required: !isView,
            message: '请上传宠物快照',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '宠物昵称',
        prop: 'nickName',
        rules: [
          {
            required: !isView,
            message: '请输入宠物昵称',
            pattern: '[^ \x22]+',
            trigger: 'blur',
          },
          {
            min: 1,
            max: 20,
            message: '长度不能超过20个字符',
            trigger: 'blur',
          },
          {
            validator: (rule, value, callback) => {
              if (value !== value.trim()) {
                callback(new Error('宠物昵称不能包含首尾空格'));
              } else {
                callback();
              }
            },
            trigger: 'blur',
          },
        ],
      },
      {
        label: '宠物编号',
        prop: 'code',
        display: isView,
      },
      {
        label: '性别',
        prop: 'gender',
        type: 'select',
        dicUrl: '/admin/dict/type/pet_sex',
        rules: [
          {
            required: !isView,
            message: '请选择宠物性别',
          },
        ],
      },
      {
        label: '宠物品种',
        prop: 'petType',
        search: true,
        type: 'cascader',
        dicUrl: '/core/classify/tree',
        rules: [
          {
            required: !isView,
            message: '请选择宠物品种',
            trigger: 'blur',
            type: 'array',
          },
        ],
      },
      {
        label: '身长（cm）',
        prop: 'height',
        rules: [
          {
            required: false,
            message: '请输入身长',
          },
          {
            required: false,
            min: 0,
            max: 1000000,
            validator: (rule, value, callback) =>
              numberValidate(rule, value, callback, 10, 2),
          },
        ],
      },
      {
        label: '颈围',
        prop: 'neckSize',
        rules: [
          {
            required: false,
            message: '请输入颈围',
          },
          {
            required: false,
            min: 0,
            max: 1000000,
            validator: (rule, value, callback) =>
              numberValidate(rule, value, callback, 10, 2),
          },
        ],
      },
      // {
      //   label: '病史',
      //   prop: 'medicalHistory',
      //   maxlength: 200,
      //   slot: true,
      //   rules: [
      //     {
      //       required: false,
      //       message: '请输入病史',
      //     },
      //   ],
      // },
      {
        label: '驱虫情况',
        prop: 'insectRepellent',
        type: 'select',
        dicData: [
          {
            label: '未知',
            value: '0',
          },
          {
            label: '未驱虫',
            value: '1',
          },
          {
            label: '已体内驱虫',
            value: '2',
          },
          {
            label: '已体外驱虫',
            value: '3',
          },
          {
            label: '已体外+体内驱虫',
            value: '4',
          },
        ],
        rules: [
          {
            required: !isView,
            message: '请选择驱虫情况',
          },
        ],
      },
      {
        type: 'select',
        label: '绝育情况',
        prop: 'sterilization',
        rules: [
          {
            required: !isView,
            message: '请选择绝育情况',
          },
        ],
        dicUrl: '/admin/dict/type/sterilization',
      },
      {
        type: 'select',
        label: '疫苗情况',
        prop: 'vaccine',
        rules: [
          {
            required: !isView,
            message: '请选择疫苗情况',
          },
        ],
        dicUrl: '/admin/dict/type/vaccine',
      },
      {
        label: '收养来源',
        prop: 'adoptionSource',
        slot: true,
        type: 'select',
        dicData: ADOPTION_SOURCE_List,
        rules: [
          {
            required: true,
            message: '请选择收养来源',
          },
        ],
        control: (val, form) => {
          return {
            givenName: {
              display: val === '2',
            },
          };
        },
      },
      {
        label: '送养人',
        prop: 'givenName',
        slot: true,
        type: 'select',
        display: false,
        rules: [
          {
            required: false,
            message: '请选择送养人',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '项圈编号',
        prop: 'collarNumber',
        search: true,
        rules: [
          {
            required: false,
            message: '请输入项圈编号',
          },
          {
            max: 20,
            message: '长度不能超过20个字符',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '芯片编号',
        prop: 'chip',
        rules: [
          {
            required: false,
            message: '请输入芯片编号',
          },
          {
            max: 20,
            message: '长度不能超过20个字符',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '爱心收容站',
        prop: 'baseId',
        dicUrl: '/core/base/list',
        type: 'select',
        props: {
          label: 'name',
          value: 'id',
        },
        rules: [
          {
            required: !isView,
            message: '请选择爱心收容站',
          },
        ],
      },
      {
        label: '收容站位置',
        prop: 'baseAddress',
        disabled: true,
        rules: [
          {
            required: !isView,
            message: '',
          },
        ],
      },
      {
        label: '出生日期',
        prop: 'birthDay',
        type: 'date',
        format: 'yyyy-MM-dd',
        slot: true,
        valueFormat: 'yyyy-MM-dd',
        rules: [
          {
            required: !isView,
            message: '请选择出生日期',
          },
        ],
      },
      // {
      //   label: '年龄段',
      //   prop: 'ageGroup',
      //   type: 'select',
      //   // dicUrl: `/core/attribute/list/bind/CAT/ageGroup`,
      //   props: {
      //     label: 'attributeName',
      //     value: 'attributeCode',
      //   },
      //   rules: [
      //     {
      //       required: true,
      //       message: '请选择年龄段',
      //       trigger: 'blur',
      //     },
      //   ],
      // },
      {
        label: '收养日期',
        prop: 'receiveDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        search: true,
        width: 160,
        searchRange: true,
        rules: [
          {
            required: !isView, // 详情的时候这个字段不要校验，因为旧数据， 此字段为非必填项
            message: '请选择收养日期',
          },
        ],
      },
      {
        label: '体型',
        prop: 'bodilyForm',
        type: 'select',
        rules: [
          {
            required: false,
            message: '请选择体型',
          },
        ],
        // dicUrl: `/core/attribute/list/bind/CAT/bodilyForm`,
        props: {
          label: 'attributeName',
          value: 'attributeCode',
        },
      },
      {
        label: '体重（kg）',
        prop: 'weight',
        type: 'number',
        rules: [
          {
            required: !isView,
            trigger: 'change',
            pattern: '[^ \x22]+',
            message: '请输入体重',
            type: 'number',
          },
          {
            required: !isView,
            max: 100000000,
            min: 0,
            validator: (rule, value, callback) =>
              numberValidate(rule, value, callback, 8, 2),
          },
        ],
      },
      {
        label: '毛色',
        prop: 'furColor',
        type: 'select',
        rules: [
          {
            required: !isView,
            message: '请选择毛色',
          },
        ],
        // dicUrl: `/core/attribute/list/bind/CAT/furColor`,
        props: {
          label: 'attributeName',
          value: 'attributeCode',
        },
      },
      {
        label: '毛发长度',
        prop: 'hairLength',
        type: 'select',
        rules: [
          {
            required: false,
            message: '请选择毛发长度',
          },
        ],
        // dicUrl: `/core/attribute/list/bind/CAT/hairLength`,
        props: {
          label: 'attributeName',
          value: 'attributeCode',
        },
      },
      {
        label: '是否患病',
        prop: 'sick',
        formslot: true,
        type: 'select',
        span: 24,
        dicData: IF_ILL_LIST,
        rules: [
          {
            required: !isView,
            message: '请选择是否患病',
          },
        ],
      },
      {
        label: '宠物状态',
        prop: 'status',
        display: isView,
        type: 'select',
        dicData: PET_STATE_LIST,
      },
      {
        label: '领养日期',
        prop: 'adoptionDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        width: 120,
        searchRange: true,
        display: isView,
      },
      {
        label: '备注',
        prop: 'remark',
        type: 'textarea',
        showWordLimit: true,
        maxlength: 100,
        minRows: 7,
        rules: [
          {
            required: false,
            message: '请输入备注',
          },
        ],
        span: 24,
      },
    ],
  };
};
